package com.zhl.projectmerger.strategy;

import com.zhl.projectmerger.ProjectMergeConfig;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;


/**
 * 默认合并策略
 *
 * @author zhangHL
 */
public class DefaultMergeStrategy extends AbtractMergeStrategy {
    /**
     * 判断是否需要合并
     *
     * @param fromClass    来源类描述信息
     * @param toClass      目标类描述信息
     * @param mergerConfig 合并配置
     * @return
     */
    @Override
    public boolean match(ClassOrInterfaceDeclaration fromClass, ClassOrInterfaceDeclaration toClass, ProjectMergeConfig mergerConfig) {
        String className = fromClass.getName().getIdentifier();
        return mergerConfig.getClassNameSuffixNeedMerge().stream().anyMatch(
                classNameSuffix -> className.toLowerCase().endsWith(classNameSuffix.toLowerCase())
        );
    }

    /**
     * import 语句处理
     * 合并from中的import语句到to中
     *
     * @param from
     * @param to
     */
    @Override
    public void importProcess(CompilationUnit from, CompilationUnit to) {
        super.importProcess(from, to);
    }

    /**
     * 类注解处理
     *
     * @param from
     * @param to
     */
    @Override
    public void classFileAnnotationProcess(ClassOrInterfaceDeclaration from, ClassOrInterfaceDeclaration to) {
        super.classFileAnnotationProcess(from, to);
    }

    @Override
    protected void doFieldsMerge(FieldDeclaration fromFieldDeclaration, FieldDeclaration toFieldDeclaration) {

    }

    /**
     * 字段信息合并
     *
     * @param toClass          合并到的目标
     * @param fieldDeclaration
     */
    @Override
    public void fieldsMerge(ClassOrInterfaceDeclaration toClass, FieldDeclaration fieldDeclaration) {
       super.fieldsMerge(toClass, fieldDeclaration);
    }

    /**
     * 方法信息合并
     *
     * @param toClass
     * @param memberDeclaration
     */
    @Override
    public void methodMerge(ClassOrInterfaceDeclaration toClass, MethodDeclaration memberDeclaration) {
        super.methodMerge(toClass, memberDeclaration);
    }

    @Override
    protected void doMethodMerge(MethodDeclaration fromMethodDeclaration, MethodDeclaration toMethodDeclaration) {

    }
}
